% Basic Introduction:
% This function executes the full Newton update given the initial guess 
% X0 and the function generating [der_1,der_2] (or [f0,der_1]). 
% The function also incorporates the reflection revision given the 
% reflection bound Bound=[Left,Right].
% 
% Special Note:
% If we do not want to use the reflection revision, we can simply use Left
% as -Inf and Right as Inf.
% Function Form:
% [X1,ExitFlag]=VecNewton_FullUpdate(X0,DerFun,ItStopTol,ItStopNum,Bound)


function [X1,ExitFlag]=VecNewton_FullUpdate(X0,DerFun,ItStopTol,ItStopNum,Bound)

diff    =   1;
count   =   0;
der     =   DerFun(X0);
if nargin<=4
    while diff>ItStopTol && count<=ItStopNum
        X1      =   X0-der(:,1)./der(:,2);
        X0      =   X1;
        der     =   DerFun(X0);
        diff    =   norm(der(:,1));
        count   =   count+1;
    end
else
    Left    =   Bound(:,1);
    Right   =   Bound(:,2);
    while diff>ItStopTol && count<=ItStopNum
        X1      =   VecNewton_OneStepUpdate(X0,der,Left,Right);
        X0      =   X1;
        der     =   DerFun(X0);
        diff    =   norm(der(:,1));
        count   =   count+1;
    end 
end

if count<=ItStopNum
    ExitFlag    =   1;
else
    ExitFlag    =   0;
end